﻿using AutoMapper;
using J.Model;
using J.ProductSet.Application.Command.ProductCommand;
using MediatR;
using SqlSugar;

namespace J.ProductSet.Application.CommandHandler.ProductCommandHandler
{
    public class ProductDeleteCommandHandler : IRequestHandler<ProductDeleteCommand, int>
    {
        private readonly ISqlSugarClient _sqlSugarClient;
        public IMapper _mapper;
        public ProductDeleteCommandHandler(ISqlSugarClient sqlSugarClient, IMapper mapper)
        {
            _sqlSugarClient = sqlSugarClient;
            _mapper = mapper;
        }
        public async Task<int> Handle(ProductDeleteCommand request, CancellationToken cancellationToken)
        {
            var id = request.ProductID.Split(",");
            var list = await _sqlSugarClient.Deleteable<Product>(id).ExecuteCommandAsync();
            return list;
        }
    }
}
